<?php

class User extends Base_Model {

    function __construct()
    {
        parent::__construct();
        $this->init("user","user_id","email");
    }
	
    function is_exists($user,$password)
    {
		$this->db->select("nama_user,password")
				 ->from("user")
			 ->where("nama_user","$user")
			 ->where("password",md5($password));
		$rec = $this->db->get();
		if($rec->num_rows()>0)
		{
				return TRUE;
		}
			
		return FALSE;
    }

	function email_exists($email)
	{
		$this->db->select("nama_user,password")
				 ->from("user")
			 ->where("email",$email);
		$rec = $this->db->get();
		if($rec->num_rows()>0)
		{
				return TRUE;
		}
			
		return FALSE;	
	}
	
    function update_password($user_id,$password)
    {
    	$data = array("password"=>md5($password));
    	$where = array("user_id"=>$user_id);
    	$this->update($data, $user_id);
    	
    }
    
	function get_user($user,$password)
	{
		$this->db->select("user_id,nama_user,password,has_write_access,id_role")
				 ->from("user")
			 ->where("nama_user","$user")
			 ->where("password",md5($password));
		$rec = $this->db->get();
		if($rec->num_rows()>0)
		{
			$result = $rec->result();
			return $result[0];
		}
			
		return FALSE;	
	}
	
    function add($user,$password,$email="",$anggota=null)
    {
            $data = array("nama_user"=>$user,
                          "password"=>md5($password),
			  "email"=>$email
                	  );
					  
            $this->save($data);
    }
	
}

/* End of file user.php */
/* Location: ./system/application/models/tabungan.php */